<?php
/* @var $this QuotationOrderHeaderController */
/* @var $model QuotationOrderHeader */

$this->breadcrumbs=array(
	'Quotation Order Headers'=>array('index'),
	'Create',
);
Yii::app()->clientScript->registerScript('search', "
function formatNumber (num) {
    return num.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
}

function getVal(){
    var qty=document.getElementById('qty').value;
    qty=Number(qty.replace(/[^0-9\.-]+/g,''));
    var unit=document.getElementById('unit_sell').value;
    unit=Number(unit.replace(/[^0-9\.-]+/g,''));
    $('#unit_sell_hidden').val(unit);

    return formatNumber(unit*qty);
}

$('#attention').blur(function(){
	document.getElementById('employee_id').value='".Yii::app()->session['id']."';
	return true;
});
$('#getProduct').click(function(){
	document.getElementById('employee_id').value='".Yii::app()->session['id']."';
	return true;
});


$('#qty').change(function(){
    var total=getVal();
    $('#total').val(total);
    
});

$('#unit_sell').change(function(){
    var total=getVal();
    $('#total').val(total);
});





");

$this->menu=array(
    array('label'=>'List Quotation', 'url'=>array('quotationOrderHeader/index')),
	array('label'=>'View Quotation', 'url'=>array('quotationOrderHeader/viewQuotationOrderHeader','id'=>$quo_no)),
);
?>

<h1>Add Item Quotation</h1>

<?php $this->renderPartial('_form', array('model'=>$model,'quo_no'=>$quo_no,'unit_sell'=>$unit_sell,'total'=>$total)); ?>

<?php
	$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
        'id'=>'mydialog2',
        'options'=>array(
            'title'=>'Select Item <code>+</code>',
            'autoOpen'=>false,
            'width'=>"auto",
            'modal'=>true,
            'show'=>array(
                'effect'=>'blind',
                'duration'=>1000,
            ),
            'buttons'=>array(
                'Submit'=>'js:addItem',
                'Cancel'=>'js:function(){ $(this).dialog("close");}',
            ),
        ),
    ));

    /*$this->widget('zii.widgets.grid.CGridView', array(
        'dataProvider' => $modelProduct->search(),
        'filter' => $modelProduct,
        //lets tell the pager to use our own css file
        //'pager' => array('cssFile' => Yii::app()->baseUrl . '/css/gridViewStyle/gridView.css'),
        //the same for our entire grid. Note that this value can be set to "false"
        //if you set this to false, you'll have to include the styles for grid in some of your css files
        //'cssFile'=>false,
        //'cssFile' => Yii::app()->baseUrl . '/css/gridViewStyle/gridView.css',
        //changing the text above the grid can be fun
        'summaryText' => 'Showing {start} - {end} of {count} product records',
        //and you can even set your own css class to the grid container
        'htmlOptions' => array('class' => 'grid-view rounded'),
        'columns' => array(
                array(
                    'name' => 'product_pn',
                    'type' => 'raw',
                    'value' => 'CHtml::encode($data->product_pn)',
                    'htmlOptions'=>array('style' => 'text-align: center;'),
                ),
                array(
                    'name' => 'brands',
                    'type' => 'raw',
                    'value' => 'CHtml::encode($data->brands)',
                    'htmlOptions'=>array('style' => 'text-align: center;'),
                ),
                array(
                    'name'=>'unit_buy',
                    'type'=>'raw',
                    'filter'=>false,
                    'value'=>'CHtml::encode($data->unit_buy)',
                    'htmlOptions'=>array('style' => 'text-align: center;'),
                ),
                array(
                    'header'=>'SELECT',
                    'type'=>'raw',
                    'value'=>'CHtml::Button(
                          "+"
                          , array(
                    "class" => "btn submit"
                          , "id" => "get_link"
                          , "onClick" => "$(\"#mydialog\").dialog(\"close\");$(\"#product_pn \").val(\"". $data->product_pn."\");
                    $(\"#Dosen_nama \").val(\"". $data->unit_buy."\");
                    "))',
                ),
                //styling default buttons
               /* array(
                        'header' => '(fake) Actions',
                        'class' => 'CButtonColumn',
                        'viewButtonImageUrl' => Yii::app()->baseUrl . '/css/gridViewStyle/images/' . 'gr-view.png',
                        'updateButtonImageUrl' => Yii::app()->baseUrl . '/css/gridViewStyle/images/' . 'gr-update.png',
                        'deleteButtonImageUrl' => Yii::app()->baseUrl . '/css/gridViewStyle/images/' . 'gr-delete.png',
                ),*/
        /*),*/

    $myclass = get_class($this);
    $myclass= strstr($myclass,'Controller',true);
    
        $this->widget('application.extensions.tablesorter.Sorter', array(
    'data'=>$modelProduct,
    'columns'=>array(
        'product_pn',
        'brands',
        'unit_sell',
    ),
    'filters'=>array(
        'filter',
        'filter-select',
        'filter-false',
    ),
    'view'=>'',
    'model'=>1,
    'page'=>'addItem',
    ));
 
    $this->endWidget('zii.widgets.jui.CJuiDialog');
?>
<script type="text/javascript" >
    function addItem(){
        $(this).dialog("close");
        alert( $("#item-name-input").val() + " has been added");
    }
</script>
